<%@ page language="Java" import="java.util.*,descriptor.*,cv.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%
	SectorsListDescriptor sectPref = (SectorsListDescriptor)request.getAttribute("sectPref");
	CitiesListDescriptor citiesPref = (CitiesListDescriptor)request.getAttribute("citiesPref");
	CountriesListDescriptor countriesPref = (CountriesListDescriptor)request.getAttribute("countriesPref");
	String error1 = (String)request.getAttribute("error1");
	String notif = "";
	if(error1 != null)
	{
		notif ="<p style=\"color:red; font-size: 10px;\">" + error1 + "</p>";
	}
%>

<html>
	<jsp:include page="StudentHeader.jsp" >
		<jsp:param name="pageTitle" value="Work Placement Management System - Student" />
	</jsp:include>
	<body OnLoad="showmenu(document.getElementById('smenu4'));">
		<jsp:include page="StudentPageHeader.jsp"></jsp:include>
		<div id="container">
			<jsp:include page="StudentMenu.jsp" ></jsp:include>
			<div id="content">
				<h3 class="posttitle">Student - Companies Preferences</h3>
				<div class="entry">
					<p>Which preference do you want to set up ?</p><br>
					<form name="frmPrefList" method="post" style="margin-left: auto; margin-right: auto;">
						<input type="hidden" name="action" value="setPref"> 
						<select OnChange="document.frmPrefList.submit();" name="pref" > 
							<option value="">Select a criterion:</option>
							<option value="1">Sector</option>
							<option value="2">City</option>
							<option value="3">Country</option>
						</select>
					</form>
					<br>
					<hr>
					<%= notif %>
					<%
						if(sectPref.sizeSectorList() > 0 || citiesPref.sizeCitiesList() > 0 || countriesPref.sizeCountriesList() > 0)
						{
					%>
						<h4>Preferences</h4>
						<table rules="all">
							<thead>
								<tr>
									<th>Preference</th><th>Name</th><th>Actions</th>
								</tr>
							</thead>
							<tbody>
								<%
									int size = sectPref.sizeSectorList();
									if(size > 0)
									{
								%>	
									<tr>
										<td rowspan="<%= size %>"><h4>Sector</h4></td>
							
								<%		for(int i=0 ; i<size ; i++)
										{
											if(i == 0)
											{
								%>
										<td><%= sectPref.getSectorDescriptors().elementAt(i).getName() %></td>
										<td rowspan="<%= size %>">
											<form name="editSector" method="post">
												<input type="hidden" name="action" value="setPref">
												<input type="hidden" name="pref" value="1">    
											</form> 
											<a href="javascript:document.editSector.submit();" title="Edit Sector's Preferences">Edit</a>
											<form name="deleteSector" method="post">
												<input type="hidden" name="action" value="delPref">
												<input type="hidden" name="pref" value="1"> 
												<input id="sectordelete" type="hidden" name="filename" value="Sector's Preferences">    
											</form> 
											<a href="javascript:openDeleteWindow(document.getElementById('sectordelete'),document.deleteSector);" title="Delete all Sector's Preferences">Delete</a>
										</td>
									</tr>
								<% 
											}
											else
											{
								%>
										<tr><td><%= sectPref.getSectorDescriptors().elementAt(i).getName() %></td></tr>
								<%
											}
										}
									}
									int size1 = citiesPref.sizeCitiesList();
									if(size1 > 0)
									{
								%>	
									<tr>
										<td rowspan="<%= size1 %>"><h4>City</h4></td>
							
								<%		for(int i=0 ; i < size1 ; i++)
										{
											if(i == 0)
											{
								%>
										<td><%= citiesPref.getCityDescriptors().elementAt(i).getName() %></td>
										<td rowspan="<%= size1 %>">
											<form name="editCity" method="post">
												<input type="hidden" name="action" value="setPref">
												<input type="hidden" name="pref" value="2">    
											</form> 
											<a href="javascript:document.editCity.submit();" title="Edit City's Preferences">Edit</a>
											<form name="deleteCity" method="post">
												<input type="hidden" name="action" value="delPref">
												<input type="hidden" name="pref" value="2"> 
												<input id="deleteCity" type="hidden" value="City's Preferences">    
											</form> 
											<a href="javascript:openDeleteWindow(document.getElementById('deleteCity'),document.deleteCity);" title="Delete all City's Preferences">Delete</a>
										</td>
									</tr>
								<% 
											}
											else
											{
								%>
									<tr><td><%= citiesPref.getCityDescriptors().elementAt(i).getName() %></td></tr>
								<%
											}
										}
									}
									
									int size2 = countriesPref.sizeCountriesList();
									if(size2 > 0)
									{
								%>	
									<tr>
										<td rowspan="<%= size2 %>"><h4>Country</h4></td>
							
								<%		for(int i=0 ; i < size2 ; i++)
										{
											if(i == 0)
											{
								%>
										<td><%= countriesPref.getCountryDescriptors().elementAt(i).getName() %></td>
										<td rowspan="<%= size2 %>">
											<form name="editCountry" method="post">
												<input type="hidden" name="action" value="setPref"> 
												<input type="hidden" name="pref" value="3">    
											</form> 
											<a href="javascript:document.editCountry.submit();" title="Edit Country's Preferences">Edit</a>
											<form name="deleteCountry" method="post">
												<input type="hidden" name="action" value="delPref">
												<input type="hidden" name="pref" value="3"> 
												<input id="deleteCountry" type="hidden" value="Country's Preferences">    
											</form> 
											<a href="javascript:openDeleteWindow(document.getElementById('deleteCountry'),document.deleteCountry);" title="Delete all Country's Preferences">Delete</a>
										</td>
									</tr>
								<% 
											}
											else
											{
								%>
									<tr><td><%= countriesPref.getCountryDescriptors().elementAt(i).getName() %></td></tr>
								<%
											}
										}
									}
								%>
									</tbody>
								</table>
								<br>
								<form name="relevantCompanies" method="post">
									<input type="hidden" name="action" value="relevantCompanies">
									<button type="submit">View Relevant Companies</button>   
								</form> 
								<%
							}
								%>
				</div>
			</div>
			<jsp:include page="StudentPageFooter.jsp"></jsp:include>
		</div>
	</body>
</html>